package com.domain;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.hibernate.CallbackException;
import org.hibernate.Session;
import org.hibernate.classic.Lifecycle;

@Entity
public class Member implements Lifecycle {

    @Override
    public boolean onDelete(Session arg0) throws CallbackException {
        System.out.println(arg0);
        return false;
    }

    @Override
    public void onLoad(Session arg0, Serializable arg1) {
        System.out.println(arg0);
    }

    @Override
    public boolean onSave(Session session) throws CallbackException {
        System.out.println(session.getTransaction().isActive());
        return false;
    }

    @Override
    public boolean onUpdate(Session arg0) throws CallbackException {
        System.out.println(arg0);
        return false;
    }

    @Id
    @GeneratedValue
    private Integer id;
    
    private String name;
    
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinColumn(name = "department_id")
    private Department department;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }
    
}
